import Vue from 'vue'

// 懒加载
import { Lazyload, Checkbox, NavBar } from 'vant'
Vue.use(Lazyload).use(Checkbox).use(NavBar)
// 基础提示
import { Toast } from 'vant'

/**
 * @description 全局加载层
 * @param {*} index
 * @param {*} text
 */
Vue.prototype.$baseLoading = (text = '正在加载中', loadtype = 'spinner') => {
  return Toast.loading({
    message: text,
    forbidClick: true,
    loadingType: loadtype,
  })
}

Vue.prototype.$baseToast = (msg, type = 'nomal') => {
  switch (type) {
    case 'noaml':
      Toast(msg)
      break
    default:
      Toast(msg)
  }
}
// alert
import { Dialog } from 'vant'
Vue.prototype.$baseAlert = (msg, title = '', callBack) => {
  if (title) {
    Dialog.alert({
      title: title,
      message: msg,
    }).then(() => {
      if (callBack) callBack()
    })
  } else {
    Dialog.alert({
      message: msg,
    }).then(() => {
      if (callBack) callBack()
    })
  }
}
